package com.itHsuSE.demo1;

import java.util.Arrays;
import java.util.Scanner;

public class Array01 {
    public static void main(String[] args) {
        int[] arr={24,69,80,57,13};
        System.out.println("排序前：");
        System.out.println(Arrays.toString(arr));
        for (int i = 0; i < arr.length-1; i++) {
            boolean flag=true;
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j]>arr[j+1]){
                    int temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                    flag=false;
                }
            }
            if(flag){
                break;
            }
        }
        System.out.println("排序后；");
        System.out.println(Arrays.toString(arr));
    }
    public static void main3(String[] args) {
        Scanner sc=new Scanner(System.in);
        char c;
        int[] arr={1,2,3};
        do {
            int[] arrNew=new int[arr.length+1];
            for (int i = 0; i < arr.length; i++) {
                arrNew[i]=arr[i];
            }
            System.out.println("请输入数组要新添加的1个数据：");
            arrNew[arrNew.length-1]=sc.nextInt();
            arr=arrNew;
            System.out.println("数组此时的数据为：");
            for (int i = 0; i < arr.length; i++) {
                System.out.print(arr[i]+" ");
            }
            System.out.println();
            System.out.println("添加成功，请问是否需要继续添加：(y/n)");
            c=sc.next().charAt(0);
        }while (c=='y');


    }
    public static void main2(String[] args) {
        char[] chars=new char[26];
        for (int i = 0; i < chars.length; i++) {
            chars[i]=(char)('A'+i);
        }
        for (int i = 0; i < chars.length; i++) {
            System.out.print(chars[i]);
        }
    }
    public static void main1(String[] args) {
        Scanner sc=new Scanner(System.in);
        double[] arr=new double[5];
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第"+(i+1)+"个元素的值：");
            arr[i]=sc.nextDouble();
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.println("第"+(i+1)+"个元素的值为："+arr[i]);
        }
    }
}
